package com.run.wz.test;

import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;

import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.GeneratedMessage;
import com.run.wz.center.utils.ProtocolType;

public class Scan_Actionlog {
	
	private static Configuration conf;
	private static HTable table;
	private static ResultScanner scanner;
	private static void init() throws IOException {
		conf = new Configuration();
		conf.set("hbase.zookeeper.quorum",
				"DG1HB3,DG1HB4,DG1HB5");
		conf.set("hbase.zookeeper.property.clientPort", "2181");
		
		
		table = new HTable(conf, "actionlog1_201305");
		scanner = table.getScanner(new byte[]{(byte)49});
	}
	
	public static void main(String[] args) throws IOException {
		init();
		Result[] next = scanner.next(1);
		KeyValue[] raw = next[0].raw();
		for (int i = 0; i < raw.length; i++) {
			KeyValue keyValue = raw[i];
			byte[] qualifier = keyValue.getQualifier();
			ProtocolType protocolTypeByNum = ProtocolType.getProtocolTypeByNum(qualifier[0]);
			GeneratedMessage parseFrom = protocolTypeByNum.parseFrom(keyValue.getValue());
			Map<FieldDescriptor, Object> allFields = parseFrom.getAllFields();
			for(Entry<FieldDescriptor, Object> entry : allFields.entrySet()){
				System.out.println(entry.getKey().getNumber()+" "+entry.getValue());
				System.out.println(entry.getKey().getName()+" "+entry.getValue());
				if(entry.getKey().getNumber()==1) {
				}
			}
			
		}
		scanner.close();
		table.close();
	}

}
